using UnityEngine;
using System.Collections;
using System.Collections.Generic;


public class AvConfigManager : Singleton<AvConfigManager>
{
	public static Dictionary<string, IConfigDataTable> configList = new Dictionary<string, IConfigDataTable>();
	
	public static ConfigLevel configLevel; 
	public static ConfigString configString;   

    private void LoadDataConfig<TConfigTable>(ref TConfigTable configTable, params string[] dataPaths) where TConfigTable : IConfigDataTable, new()
	{
       
		try
		{
			//if (configTable == null)//alway news
				configTable = new TConfigTable();
			#if !USING_ASSETLOADER
			configTable.BeginLoadAppend();
			#endif
			foreach (var path in dataPaths)
			{
				#if !USING_ASSETLOADER
				configTable.LoadFromAssetPath(path);
				#endif
				configList[path] = configTable;

			}
			#if !USING_ASSETLOADER
			configTable.EndLoadAppend();
			#endif
			//Debug.LogWarning("Config loaded:"+ configTable.GetName());
		}
		catch (System.Exception ex)
		{
            Debug.LogError("Load Config Error:"+ configTable.GetName()+", "+ ex.ToString());
		}
	}


	
	public void LoadAll()
    {
		Debug.LogWarning("load data config");
		LoadDataConfig<ConfigLevel>(ref configLevel,"Config/ConfigLevel");
		//LoadDataConfig<ConfigString>(ref configString,"Config/ConfigString_Normal");
	}

	public void UnLoad()
	{
		foreach(KeyValuePair<string, IConfigDataTable>item in configList)
			item.Value.Clear();
		configList.Clear();
	}




}
